package com.bjshiwei.zhengu.utils;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * @author sanjin
 * @desc PrefUtil工具类
 * @time 2016/9/23 0023 上午 11:28
 */
public class PrefUtil {

    private static SharedPreferences mSharedPreferences;
    private static SharedPreferences.Editor mEditor;
    public static final String KEY_APPPLICATION_SPF_MAIN = "SW_APPLICATION_SPF_MAIN";
    public static final String KEY_LANDING_PAGE_SHOWN = "KEY_LANDING_PAGE_SHOWN";
    private static PrefUtil mInstance = null;

    public synchronized static PrefUtil getInstance(Context context) {
        if (null == mInstance) {
            mInstance = new PrefUtil(context);
        }
        return mInstance;
    }

    private PrefUtil(Context context) {
        mSharedPreferences = context.getSharedPreferences(KEY_APPPLICATION_SPF_MAIN, Activity.MODE_PRIVATE);
        mEditor = mSharedPreferences.edit();
    }

    public String getString(String key) {
        return mSharedPreferences.getString(key, null);
    }

    public boolean getLandingPageShown() {
        boolean isShown = mSharedPreferences.getBoolean(KEY_LANDING_PAGE_SHOWN, false);
        mEditor.putBoolean(KEY_LANDING_PAGE_SHOWN, true).commit();
        return isShown;
    }


    /**
     * 保存进入状态
     */

    public void saveLogined() {
        mEditor.putInt("ISLOGIN", 1).commit();
    }

    /**
     * 获取进入状态
     */
    public int getLogined() {
        return mSharedPreferences.getInt("ISLOGIN", 0);
    }


    public void saveUser(String user) {
        mEditor.putString("USERINFO", user).commit();
    }

    public String getUser() {
        return mSharedPreferences.getString("USERINFO", null);
    }

    public void saveIndividual(String individual) {
        mEditor.putString("INDIVIDUAL", individual).commit();
    }

    public String getIndividual() {
        return mSharedPreferences.getString("INDIVIDUAL", null);
    }


    public void delIndividual(){

    }


    public void removeIndividual(){mEditor.remove("INDIVIDUAL").commit();}

    public void removeUser() {
        mEditor.remove("USERINFO").commit();
    }

    /**
     * 保存进入状态
     */

    public void saveFirstIn(int flag) {
        mEditor.putInt("FLAG", flag).commit();
    }

    /**
     * 获取进入状态
     */
    public int getFirstIn() {
        return mSharedPreferences.getInt("FLAG", 0);
    }

    public void saveColor(String color){mEditor.putString("color",color).commit();}

    public String getColor(){return mSharedPreferences.getString("color",null);}

    /**
     * 保存版本名字
     *
     * @param
     */
    public void saveVersionName(String VersionName) {
        mEditor.putString("Version_Name", VersionName).commit();
    }

    /**
     * 获取版本名字
     */
    public String getVersionName() {
        return mSharedPreferences.getString("Version_Name", null);
    }

    /**
     * 保存当前应用的版本号
     *
     * @param versionCode
     */
    public void saveVersionCode(String versionCode) {
        mEditor.putString("VERSION_CODE", versionCode).commit();
    }

    /**
     * 获取当前应用的版本号
     *
     * @return
     */
    public String getVersionCode() {
        return mSharedPreferences.getString("VERSION_CODE", "1.0.0");
    }
}



